/*


 */

package jas.rpc.server;

import jas.rpc.RemoteObject;
import jas.rpc.client.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;

/**
 *
 *
 */
public class RpcServerObjectInputStream extends ObjectInputStream {
    
    private ObjectIdBank ids;
    
    public RpcServerObjectInputStream(InputStream stream, ObjectIdBank ids) throws IOException {
        super(stream);
        this.ids = ids;
        enableResolveObject(true);
    }
    
    @Override
    protected Object resolveObject(Object o) throws IOException {
        if (o != null && o instanceof RemoteObject) {
            RemoteObject remote = (RemoteObject) o;
            return ids.getObjectWithId(remote.getId());
        }
        return o;
    }
    
}
